home *** CD-ROM | disk | FTP | other *** search
- Path: engnews1.Eng.Sun.COM!taumet!clamage
- From: peng@dpg.rnb.com (Wei Peng)
- Newsgroups: comp.std.c++
- Subject: Temporary objects in Std
- Date: 17 Apr 1996 14:57:29 GMT
- Organization: Sun Microsystems Inc., Mountain View, CA
- Approved: clamage@eng.sun.com (comp.std.c++)
- Message-ID: <4107cc$101229.223@news>
- NNTP-Posting-Host: taumet.eng.sun.com
- X-Newsreader: knews 0.9.6
- Originator: clamage@taumet
-
- Hi, I'm sure about what the Std says about the lifetime of temp objects (it
- says tmp objects may live longer... or something alike).
-
- A sample code. Suppose we have a string object called String, all necessary
- constructors/operators are well defined. Now we have three functions
-
- void doSomething(const char*);
-
- String getString();
-
- const char* getCharStar()
- {
- return returnString();
- }
-
- Now if we do:
-
- doSomething(getCharStar());
-
- Obvously this code doesn't work under old C++, where temp objects only
- live within their scope. My impression is that under STD C++ the tmp
- object created by getString() should live long enough so doSomething()
- can safely execute.
-
- But apparently some of the compilers I've tried still execute String
- destructor when getCharStar() returns.
-
- Wei Peng
-
-
- [ comp.std.c++ is moderated. To submit articles: try just posting with ]
- [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
- [ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
- [ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
- [ Comments? mailto:std-c++-request@ncar.ucar.edu ]
-